import Vue from 'vue'
import VueI18n from 'vue-i18n'
import Cookies from 'js-cookie'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
import enLocale from 'element-ui/lib/locale/lang/en'
import ElementLocale from 'element-ui/lib/locale'
//引入各个语言的配置
import cn from './cn';
import en from './en';

Vue.use(VueI18n);
const initLocale = Cookies.get('locale') || 'zh';
let lang = 'zh'
if (initLocale == "en") {
    lang = 'en'
    Cookies.set('locale', lang);
}

const i18n = new VueI18n({
  locale:Cookies.get('locale') || lang,
  messages:{
    'zh':Object.assign(cn,zhLocale),
    'en':Object.assign(en,enLocale),
  }
})

ElementLocale.i18n((key, value) => i18n.t(key, value))

export default i18n